package edu.gym4all.data.connection;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import edu.gym4all.data.ConnectionDB;
import edu.gym4all.util.AppConfig;

public class MySqlConnection implements ConnectionDB {

	@Override
	public Connection getConnection() throws InstantiationException,
			IllegalAccessException, ClassNotFoundException, SQLException {
		String user = "root";
		String password = ""; // senha utilizada para home project, DEFAULT =
								// vazio
		String nomeDoEsquema = "Gym4All";
		String url = "jdbc:mysql://localhost:3306/" + nomeDoEsquema;

		// Quem fara, de fato, a conexao com o banco de dados
		Class.forName("com.mysql.jdbc.Driver").newInstance();

		// Obtem uma via de comunicao com o banco de dados
		Connection con = DriverManager.getConnection(url, user, password);
		return con;
	}

	public String getDbUrl() {
		return AppConfig.getString("db_url");
	}
}